﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CLSWindowsApp
{
    public partial class Form1 : Form
    {
        private Icon m_info = new Icon(SystemIcons.Information,40,40);
        private Icon m_error = new Icon(SystemIcons.Error, 40, 40);

        private Icon m_ready = new Icon(SystemIcons.WinLogo, 40, 40);

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txtSource.Text = "D:\\Creative\\Source";
            txtDest.Text = "D:\\Creative\\Destination";
            txtProcessedFile.Text = "D:\\Creative\\Processed";
            optGenerateLog.Checked = true;


        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(txtSource.Text))
            {
                errMessage.SetError(txtSource, "Invalid Source Directrory");
                txtSource.Focus();
                tabControl1.SelectedTab = tabSource;
                return;
            }
            else {
                errMessage.SetError(txtSource,"");
            }
            if (!System.IO.Directory.Exists(txtDest.Text))
            {
                errMessage.SetError(txtDest, "Invalid Source Directrory");
                txtDest.Focus();
                tabControl1.SelectedTab = tabDest;
                return;
            }
            else
            {
                errMessage.SetError(txtDest, "");
            }
            if (!System.IO.Directory.Exists(txtProcessedFile.Text))
            {
                errMessage.SetError(txtProcessedFile, "Invalid Source Directrory");
                txtProcessedFile.Focus();
                tabControl1.SelectedTab = tabSource;
                return;
            }
            else
            {
                errMessage.SetError(txtProcessedFile, "");
            }
            //watch directory 
            watchDir.EnableRaisingEvents = true;
            watchDir.Path = txtSource.Text;
            //set icon 
            icuNotify.Icon = m_ready;
            icuNotify.Visible = true;
            this.Hide();//hide main window
        }

        private void txtSource_KeyUp(object sender, KeyEventArgs e)
        {
            if (!System.IO.Directory.Exists(txtDest.Text))
            {
                txtSource.BackColor = Color.Pink;
            }
            else {
                txtSource.BackColor = Color.White;
            }
        }

        private void txtDest_KeyUp(object sender, KeyEventArgs e)
        {
            if (!System.IO.Directory.Exists(txtDest.Text))
            {
                txtDest.BackColor = Color.Pink;
            }
            else
            {
                txtDest.BackColor = Color.White;
            }

        }

        private void txtProcessedFile_KeyUp(object sender, KeyEventArgs e)
        {
            if (!Directory.Exists(txtProcessedFile.Text))
            {
                txtProcessedFile.BackColor = Color.Pink;
            }
            else
            {
                txtProcessedFile.BackColor = Color.White;
            }
        }

        private void txtSource_TextChanged(object sender, EventArgs e)
        {
            if (!System.IO.Directory.Exists(txtSource.Text))
            {
                txtSource.BackColor = Color.Pink;
            }
            else
            {
                txtSource.BackColor = Color.White;
            }
        }

        private void mnuConfiguer_Click(object sender, EventArgs e)
        {
            icuNotify.Visible = false;
            this.ShowInTaskbar = true;
            this.Show();
        }

        private void mnuExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void icuNotify_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            icuNotify.Visible = false;
            this.ShowInTaskbar = true;
            this.Show();
        }
    }
    }


